package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        try(
                Connection connection = DBUtil.getConnection();
                Scanner scan = new Scanner(System.in)
        ) {
            Statement statement = connection.createStatement();
//            System.out.println("请输入要删除的用户名:");
//            String str = scan.nextLine();
//            String sql = "DELETE FROM userinfo WHERE username = '" +
//                     str+"'";
            UserInfo userInfo = InputUtil.getInputObject(new UserInfo(),"删除用户","删除");
            String sql = "DELETE FROM userinfo WHERE username = '" +
                     userInfo.getUsername()+"'";
            int num = statement.executeUpdate(sql);
            if (num>1){
                System.out.println("删除成功");
            }else {
                System.out.println("删除失败");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
